import { createStore } from './my-redux'
import { combineReducers } from './my-combineReducers'

// reduce
function counter(state = 100, action) {
  switch (action.type) {
    case 'add':
      return state + 1
    case 'cut':
      return state - 1
    default:
      return state
  }
}

function num(state = 10, action) {
  switch (action.type) {
    case 'add':
      return state + 1
    case 'cut':
      return state - 1
    default:
      return state
  }
}

let rootReducers = combineReducers({counter, num})
const store = createStore(rootReducers)

store.subscribe(listen)

function listen() {
  // console.log(arguments)
  console.log(store.getState())
}

const init = store.getState()
console.log(init)

store.dispatch({type: 'add'})
store.dispatch({type: 'add'})
store.dispatch({type: 'add'})
store.dispatch({type: 'add'})
console.log(store.getState())


/**
 * @function createStore
 * @function dispatch
 * @function subscribe
 * @function reduce
 */